<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>穿梭框组件</title>
    <link href="./../resources/js/plugins/layui/css/layui.css" type="text/css" rel="stylesheet"  />
    <script type="text/javascript" src="./../resources/js/plugins/layui/layui.js"></script>
    <style>

        .layui-table-tool{
            line-height: 50px;
            background: #EEF1F8;
            padding: 0px;
            color: #000000;
        }

        .layui-table-tool-temp{
            padding-right: 10px;
        }

        .layui-table-cell .layui-form-checkbox[lay-skin=primary] {
            top: 0px;
        }
    </style>
</head>
<body>
<div class="layui-container" style="margin-top: 15px;">


    <div id="jobsTransfer"></div>
    <div class="layui-row" style="text-align: center">
        <div  >
            <button class="layui-btn blue-btn" id="btn_save" style="background-color: #1E85EC;color: #fff;">保存</button>
            <button class="layui-btn blue-btn" id="btn_canel" style="margin-left: 10px;background-color: #1E85EC;color: #fff;">取消</button>
        </div>
    </div>
    <div id="root1"></div>
</div>

</body>

<script>
    layui.config({
        base: '../../resources/js/plugins/layui_exts/transfer/'
    }).use(['transfer'],function () {
        var transfer = layui.transfer,$ = layui.$;
        //数据源
        var data1 = [];
        var data2 = [];
        //表格列
        var cols = [{type: 'checkbox', fixed: 'left'}
            , {field: 'ID', title: 'ID', width: 60, sort: false, hide: true}
            , {field: 'TEMPNAME', title: '模板名称', sort: false, minWidth: 80}
            , {field: 'JOBNAME', title: '岗位名称', sort: false, minWidth: 80}
            , {field: 'ZPCOUNT', title: '招聘人数', minWidth: 80, hide: true}
            , {field: 'WORKCONT', title: '工作内容', sort: false, hide: true, width: 90}
            , {field: 'WORKREQ', title: '专业要求', minWidth: 100, hide: true}
            , {field: 'HEIGHT', title: '身高', minWidth: 100, hide: true}
            , {field: 'VISION', title: '视力', sort: false, hide: true}
            , {field: 'WORKYEAR', title: '工作年限', sort: false, edit: 'text', hide: true}
            , {field: 'AGEF', title: '年龄', sort: false, templet: '#jobsAgeTpl', hide: true}
            , {field: 'AGET', title: '年龄', sort: false, hide: true, hide: true}
            , {field: 'EDUCODE', title: '学历编码', sort: false, hide: true}
            , {field: 'EDUNAME', title: '学历名称', sort: false, hide: true}
            , {field: 'MAJOR', title: '所学专业', sort: false, hide: true}
            , {field: 'ISTEMPLATE', title: '是否模版', sort: false, hide: true},
            ]
        //表格配置文件
        var tabConfig = {'page':false,'limits':[10,50,100],'height':400};
        var tb1
        $.ajax({
            url:'../../resources/test/datas/jobsTemp.json',
            dataType:'JSON',
            type:'POST',
            success:function (json) {
                data1=json.data;
                tb1 = transfer.render({
                    elem: "#jobsTransfer", //指定元素
                    cols: cols, //表格列  支持layui数据表格所有配置
                    //url: 'test/datas/flows.json',
                    data: [data1,data2], //[左表数据,右表数据[非必填]]
                    tabConfig: tabConfig //表格配置项 支持layui数据表格所有配置
                })
            }
        });

        //transfer.get(参数1:初始化返回值,参数2:获取数据[all,left,right,l,r],参数:指定数据字段)
        //获取数据
        $('#btn_save').on('click',function () {
            var data = transfer.get(tb1,'r');
            // layer.msg(JSON.stringify(data))
            var tabledatas= parent.layui.table.cache['jobsTable'];
            var hasData=false;
            var hasIndex=0;
            if(data.length>0){
                layui.each(data,function (i,t) {
                    layui.each(tabledatas,function (j,d) {
                        if(t.JOBNAME==d.JOBNAME){
                            hasData=true;
                            return;
                        }
                    });
                   // tabledatas.splice(i+1, 0, t);
                });
            }
            if(hasData){
               var findex= layer.confirm('列表中已存在相同招聘岗位!是否进行覆盖!',{icon:5,title:"提示"},function () {
                   layui.each(data,function (i,t) {
                       var needOver=false;
                       layui.each(tabledatas,function (j,d) {
                           if(t.JOBNAME==d.JOBNAME){
                               needOver=true;
                               tabledatas[j]=t;
                           }
                       });

                       if(!needOver){
                           tabledatas.push(t);
                       }
                   });
                   parent.layui.table.cache['jobsTable']=tabledatas;
                   parent.layui.table.reload('jobsTable',{data:tabledatas});
                   parent.layer.closeAll();
                },function () {
                    layer.close(findex);
                });
            }else{
                layui.each(data,function (i,t) {
                    tabledatas.push(t);
                });
                parent.layui.table.cache['jobsTable']=tabledatas;
                parent.layui.table.reload('jobsTable',{data:tabledatas});
                parent.layer.closeAll();
                //tabledatas.push(data);
            }
        });

        $('#btn_canel').on('click',function () {
            parent.layer.closeAll();
        });
    })
</script>
</html>